package com.chencs.aso.cheat.controller;

import com.alibaba.fastjson.JSON;
import com.chencs.app.AppCommon;
import com.chencs.aso.cheat.service.CheatService;
import com.chencs.vo.biz.category.CategoryModel;
import com.chencs.vo.biz.cheat.AccountModel;
import com.chencs.vo.biz.cheat.DeviceLogModel;
import com.chencs.vo.biz.cheat.DeviceModel;
import com.chencs.vo.net.request.CategoryRequest;
import com.chencs.vo.net.response.CategoryResponse;
import com.chencs.vo.net.response.ResponseBase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by fangzehua on 2017/8/28.
 */


@RestController
@RequestMapping("/app/aso")
public class CheatController {

    @Autowired
    private CheatService cheatService;

    /**
     *
     * @return
     */
    @RequestMapping(value = "/devRegister", method = RequestMethod.POST, produces = "application/json; charset=UTF-8")
    public String devRegister(@RequestBody DeviceModel model){
        System.out.println(JSON.toJSON(model));
        ResponseBase response = new ResponseBase();
       try {
           cheatService.devRegister(model);
           response.setCode(AppCommon.SUCCESS);
           }catch (Exception e){
           response.setCode(AppCommon.ERROR);
           }
        return JSON.toJSONString(response);
    }

    /**
     *
     * @return
     */
    @RequestMapping(value = "/devRegister2/{uid}/{name}/{os}",  method = RequestMethod.GET)
    public String devRegister2(@PathVariable("uid") String uid,@PathVariable("name") String name,@PathVariable("os") String os){
        System.out.println(uid+"--"+name+"---"+os);
        DeviceModel model =   new DeviceModel();
        model.setName(name);
        model.setOs(os);
        model.setUid(uid);
        ResponseBase response = new ResponseBase();
        try {
            cheatService.devRegister(model);
            response.setCode(AppCommon.SUCCESS);
        }catch (Exception e){
            response.setCode(AppCommon.ERROR);
        }
        System.out.println(JSON.toJSONString(response));
        return JSON.toJSONString(response);
    }

    /**
     *
     * @return
     */
    @RequestMapping(value = "/addDevLog2/{appid}/{uid}/{appkey}/{flag}/{accont}", method = RequestMethod.GET)
    public String addDevLog2(@PathVariable("appid") String appid,@PathVariable("uid") String uid,@PathVariable("appkey") String appkey,
                             @PathVariable("flag") String flag,@PathVariable("accont") String accont){

        DeviceLogModel model = new DeviceLogModel();
        model.setAppid(appid);
        model.setAppkey(appkey);
        model.setUid(uid);
        model.setFlag(flag);
        model.setAccont(accont);
        if(flag.equals("1")){
            model.setDescs("成功");
        }
        System.out.println(JSON.toJSON(model));
        ResponseBase response = new ResponseBase();
        try {
            cheatService.addDevLog(model);
            response.setCode(AppCommon.SUCCESS);
        }catch (Exception e){
            e.printStackTrace();
            response.setCode(AppCommon.ERROR);
        }


        return JSON.toJSONString(response);
    }





    /**
     *
     * @return
     */
    @RequestMapping(value = "/getAsoAcconut", method = RequestMethod.GET)
    public String getAsoAcconut(){
        AccountModel accountModel =  cheatService.getAccountMode();
        return JSON.toJSONString(accountModel);
    }




}
